package com.lsh.quartz;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;

/**
 * @author ：LiuShihao
 * @date ：Created in 2020/8/29 1:00 下午
 * @desc ：
 * Duration   计算两个时间(time)之间的间隔
 * Period     计算两个日期(date)之间的间隔
 */
public class SpringBootQuartzJob implements Job {
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        LocalDate start = LocalDate.of(2019, 07, 07);
        LocalDate now = LocalDate.now();
        Period between = Period.between(start, now);
        LocalDateTime startTime = LocalDateTime.of(2019, 07, 07, 0, 0, 0);
        LocalDateTime now1 = LocalDateTime.now();
        Duration between2 = Duration.between(startTime, now1);
        System.out.println("QuartzJob定时任务执行: 距离2019年7月7日已经："+between.getYears()+"年"+between.getMonths()+"个月"+between.getDays()+"天"+"———————— 一共"+between2.toDays()+"天" );
//        System.out.println("QuartzJob定时任务执行: 距离2019年7月7日总共已经："+between2.toDays()+"天" );
//        System.out.println("QuartzJob定时任务执行: 距离2019年7月7日已经："+between.toHours()+"小时" );
//        System.out.println("QuartzJob定时任务执行: 距离2019年7月7日已经："+between.toMinutes()+"分" );
//        System.out.println("QuartzJob定时任务执行: 距离2019年7月7日已经："+between.getSeconds()+"秒" );
    }

}